﻿@{
     string path ="~/pdf";
     string ccappnos = Request["ccappnos"];
     var ccList= CashCardManager.ExtractSelected(ccappnos);
     DateTime date = DateTime.Now;
     string fileName =null;
     byte[] mergeAppForms = null;
     List<byte[]> appForms = new List<byte[]>();
     
    if(ccList.Count>1){
        fileName=string.Format("cashcard_app_forms_{0}.pdf",date);
    }
    
     foreach(var c in ccList){
         string fName = UtilityManager.FillCashCardTemplate(Server.MapPath(path),c);
         if(fileName==null){
             fileName=fName;   
         }
         byte[] byteArray = UtilityManager.FileToByteArray(Server.MapPath(path)+"/"+fName);
         appForms.Add(byteArray); 
        
     }
     mergeAppForms = PDFMerger.MergeFiles2(appForms);
    
    AuditManager.Log("printCashCardForm","printCasCardForm",fileName,"",@WebSecurity.CurrentUserName,"","");
    //clear all content output from the buffer stream
    
    Response.Clear();
    //add HTTP Header to the output stream and speficy default name for the browser download dialog
    
    Response.AddHeader("Content-Disposition","attachment; filename="+fileName);
    //add header for file size
    Response.AddHeader("Content-Length",mergeAppForms.Length.ToString());
    //set HTTP Mime Type
    Response.ContentType="application/pdf";
    //Write data to the client
    Response.BinaryWrite(mergeAppForms);
    Response.Flush();
    Response.End();
}